﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-13 12:49:23
// 负责人：lvsc
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{
	
	/// <summary>
	///快递公司 数据访问层
	/// </summary>	
	internal partial class ExpressCompany
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个快递公司
    	/// </summary>
        public ExpressCompanyInfo QuerySingle(Expression<Func<ExpressCompanyInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        
        /// <summary>
    	/// 根据断言条件获获取快递公司列表
    	/// </summary>
	    public IList<ExpressCompanyInfo> QueryList(Expression<Func<ExpressCompanyInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 获取快递信息
        /// </summary>
        /// <param name="cityId"></param>
        /// <param name="bizTypeId"></param>
        /// <returns></returns>
        public IList<ExpressCompanyInfo> GetInfoByBizTypeAndCityId(int cityId, int bizTypeId)
        {
            string sql = @"SELECT a.* FROM ExpressCompany a with(nolock) 
                          inner join[ExpressFeeTpl] b with(nolock)on a.ExpressCompanyID = b.ExpressCompanyID
                          inner join[ExpressFeeTplCity] c with(nolock) on b.[ExpressFeeTplID] = c.[ExpressFeeTplID]
                          where a.IsActive = 1 and b.IsActive = 1 and c.IsActive = 1 and b.BizTypeID = @BizTypeId and c.CityID = @cityId";
            IList<ExpressCompanyInfo> list = new List<ExpressCompanyInfo>();
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(sql);
            //设置参数
            db.AddInParameter(dbc, "@cityId", DbType.Int32, cityId);
            db.AddInParameter(dbc, "@bizTypeId", DbType.Int32, bizTypeId);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                while (dr.Read())
                {
                    list.Add(SQLServerProvider.Create<ExpressCompanyInfo>(dr));
                }
            }
            return list;
        }
    }
	
}